import 'package:yp/services/api.dart';
import 'package:get/get.dart';
import 'package:sp_util/sp_util.dart';

import '../../city_information.dart';
import 'state.dart';

class Order_modify_addressLogic extends GetxController {
  final Order_modify_addressState state = Order_modify_addressState();


  @override
  void onInit() {
    super.onInit();
    var cityParams = {
      "access_token": SpUtil.getString('token'),
    };
    // Api.cityInformation(cityParams).listen((event) {
    //   // print('城市信息  event = $event');
    //   if (event['code'] == 0) {
    //     AddressInformation addressInformation = AddressInformation.fromJson(event);
    //     Map<String, dynamic> mapData = addressInformation.toJson();
    //     state.addressList = mapData['children'];
    //   }
    //   update();
    // });
  }
  void setSex(int sex) {
    state.sex = sex;
    update();
  }

  @override
  void onReady() {
    super.onReady();

    print('================>');
    print('进到了order modify address');

    state.orderNum = Get.arguments['orderNum'];
    state.userName = Get.arguments['userName'];
    state.phone = Get.arguments['phone'];
    state.region = Get.arguments['region'];
    state.addrDetail = Get.arguments['addrDetail'];

    state.controller1.text = state.userName;
    state.controller2.text = state.phone;
    state.controller3.text = state.region;
    state.controller4.text = state.addrDetail;



    print('订单号：${state.orderNum}');
    print('用户名：${state.userName}');
    print('用户电话：${state.phone}');
    print('区域：${state.region}');
    print('用户地址：${state.addrDetail}');
    update();
  }

  void updateAdress(){


    var params = {
      "access_token": SpUtil.getString('token'),
      "usr_num_id":SpUtil.getInt('empeNumId'),
      "tml_num_id" : state.orderNum,//订单号
      "consumer_adr" : state.controller4.text,
      "consumer_name" : state.controller1.text,
      "consumer_telephone" : state.controller2.text,
      "adr_type": 0
    };

    print("编辑地址的params：$params");
    //更新订单收货信息
    Api.modifyOrder(params).listen((event) {
      if(event["code"].toString() == '0'){
        print('=================>');
        Get.back(result: true);
      }
    });
  }
  //
  // /// 选择地址
  // void selectCity(value){
  //   state.provinceId = int.parse(value.provinceCode);
  //   state.cityId = int.parse(value.cityCode);
  //   state.areaId = int.parse(value.areaCode);
  //   state.controller3.text = value.province +' '+ value.city+' '+ value.area;
  //   update();
  // }

}
